""" System imports """
import logging

""" Equinox """
from events import *
from player import Player
from map import Map

""" Constants """

""" Set up logging """
_log = logging.getLogger("equinox.game")


class Game:
    """ Base class for all game objects """

    STATE_PREPARING = 'preparing'
    STATE_RUNNING = 'running'
    STATE_PAUSED = 'paused'

    #----------------------------------------------------------------------
    def __init__(self, evManager):
        self.evManager = evManager
        self.evManager.registerListener( self )

        self.state = Game.STATE_PREPARING

        self.players = [ Player(evManager) ]
        self.map = Map( evManager )
        

    #----------------------------------------------------------------------
    def start(self):
        self.map.load("testmap.xml")
        self.state = Game.STATE_RUNNING
        ev = GameStartedEvent( self )
        self.evManager.post( ev )

    #----------------------------------------------------------------------
    def notify(self, event):
        if isinstance( event, TickEvent ):
            if self.state == Game.STATE_PREPARING:
                self.start()